package gogs_hook

import "atomgit.com/openlinksaas-org/proto-gen-go.git/events/events_gogs"

type PushHook struct {
	Ref        string      `json:"ref"`
	Before     string      `json:"before"`
	After      string      `json:"after"`
	CompareUrl string      `json:"compare_url"`
	Commits    []*Commit   `json:"commits"`
	Repo       *Repository `json:"repository"`
	Pusher     *User       `json:"pusher"`
	Sender     *User       `json:"sender"`
}

func (item *PushHook) ToProtoBuf() *events_gogs.PushEvent {
	ret := &events_gogs.PushEvent{
		Ref:        item.Ref,
		Before:     item.Before,
		After:      item.After,
		CompareUrl: item.CompareUrl,
		Commits:    []*events_gogs.Commit{},
		Repo:       []*events_gogs.Repository{},
		Pusher:     []*events_gogs.User{},
		Sender:     []*events_gogs.User{},
	}
	if item.Commits != nil {
		for _, commit := range item.Commits {
			if commit != nil {
				ret.Commits = append(ret.Commits, commit.ToProtoBuf())
			}
		}
	}
	if item.Repo != nil {
		ret.Repo = append(ret.Repo, item.Repo.ToProtoBuf())
	}
	if item.Pusher != nil {
		ret.Pusher = append(ret.Pusher, item.Pusher.ToProtoBuf())
	}
	if item.Sender != nil {
		ret.Sender = append(ret.Sender, item.Sender.ToProtoBuf())
	}
	return ret
}
